package com.mes.controller.manu;

import com.mes.service.manu.CutJobService;
import com.yy.base.page.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("cutJob")
public class CutJobController {
    @Autowired
    private CutJobService cutJobService;
    //加载裁断作业单
    @ResponseBody
    @RequestMapping(value="selectCutJobList",method= RequestMethod.POST)
    public Message selectCutJobList(HttpServletRequest request){
        Message msg = new Message();
        msg.setData("cutJobList",cutJobService.selectCutJobList());
        return msg;
    }
    //通过RFID工单号加载裁断作业单
    @ResponseBody
    @RequestMapping(value="selectCutJobByCode",method= RequestMethod.POST)
    public Message selectCutJobByCode(HttpServletRequest request){
        Message msg = new Message();
        String code = null;
        if(request.getParameter("code")!=null){
            code =request.getParameter("code").toString();
        }
        Map map = new HashMap<String,String>();
        map.put("code",code);
        msg.setData("cutJobDataByCode",cutJobService.selectCutJobByCode(map));
        return msg;
    }
    //报工提交
    @ResponseBody
    @RequestMapping(value="submitData",method= RequestMethod.POST)
    public Message submitData(HttpServletRequest request){
        Message msg = new Message();
        String status = null;
        String emesoJobOrderExeId = null;
        String userCode = request.getParameter("userCode");
        if(request.getParameter("status")!=null){
            status =request.getParameter("status").toString();
        }
        if(request.getParameter("emesoJobOrderExeId")!=null){
            emesoJobOrderExeId =request.getParameter("emesoJobOrderExeId").toString();
        }
        String userId = cutJobService.geteUserId(userCode);
        if (userId == null) {
            msg.setErrorMessage("工号[" + userCode + "]录入错误！");
            return msg;
        }
        Map map = new HashMap<String,String>();
        map.put("status",status);
        map.put("emesoJobOrderExeId",emesoJobOrderExeId);
        map.put("userId",userId);
        Boolean result = cutJobService.updateCutJobData(map);
        if(result){
            msg.setOkMessage("操作成功");
        }else{
            msg.setErrorMessage("操作失败");
        }
        return msg;
    }
}
